
#ifndef JELLY_SHARE_SRC_EMULE_PARSE_SERVER_MET_H_
#define JELLY_SHARE_SRC_EMULE_PARSE_SERVER_MET_H_

#include <vector>
#include <string>
#include "src/io/file.h"

namespace jellyfish
{
	namespace emule
	{
		class parse_server_met
		{
		public:
			struct tag_struct 
			{
				void clear()
				{
					type = 0;
					id = 0;
					value_uint64_t = 0;
					name.clear();
					value_string.clear();
					blob_size = 0;
				}
				uint8	type;
				uint8	id;
				std::string	value_string;
				uint64 value_uint64_t;
				std::string	name;
				uint32	blob_size;
			};

			struct server_block_struct 
			{
				void clear()
				{
					ip = 0;
					port = 0;
					server_name.clear();
					server_description.clear();
					ping_time = 0;
					failed_times = 0;
					preference = 0;
					dns.clear();
					max_users = 0;
					soft_files = 0;
					hard_files = 0;
					last_ping = 0;
					version.clear();
					udp_flags = 0;
					auxiliary_ports_list.clear();
					lowid_clients = 0;
					files = 0;
					users = 0;
				}
				uint32 ip;
				uint16 port;
				std::string server_name;
				std::string server_description;
				uint32 ping_time;
				uint32 failed_times;
				uint32 preference;
				std::string dns;
				uint32 max_users;
				uint32 soft_files;
				uint32 hard_files;
				uint32 last_ping;
				std::string version;
				uint32 udp_flags;
				std::string auxiliary_ports_list;
				uint32 lowid_clients;
				uint32 files;
				uint32 users;
			};
		public:
			parse_server_met();
			~parse_server_met();
			int32 parse(const char* file_path);
		private:
			inline void print_server_information(const server_block_struct& server_block);
			std::string read_ansi_string(uint16 raw_len);
			void read_tag(tag_struct* tag,server_block_struct* server);
			int32 open(const char* file_path);
			int32 is_met_file();
			parse_server_met(const parse_server_met&);
			parse_server_met& operator = (const parse_server_met&);
		private:
			io::file file_;
			std::vector<server_block_struct> servers_;
		};
	}
}


#endif  // JELLY_SHARE_SRC_EMULE_PARSE_SERVER_MET_H_